<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
use think\facade\Request;
class Faq extends Controller
{
    protected $middleware = ['VerifyLogin'];

    public function add()
    {
        $params = Request::param('', '', 'strip_tags,trim');
        $verify_result = $this->validate($params, 'Faq.add');

        if(true !== $verify_result){
            return json(['code'=>101,'msg'=>$verify_result]);
        }

        $data['tel']        = $params['tel'];
        $data['faq_type']   = $params['faq_type'];
        $data['content']    = $params['content'];
        $data['uid']        = request()->userInfo['id'];
        $data['quick_id']   = request()->quickAppId;

        $res = Db::table('quick_faq')->insert($data);

        if($res){
            return json(['code'=>0,'msg'=>'success','data'=>[]]);
        }else{
            return json(['code'=>102,'msg'=>'意见反馈提交失败','data'=>[]]);
        }

    }

    public function index()
    {
        $params = Request::get('', '', 'strip_tags,trim');
        $FaqLogic = \think\facade\App::model('Faq', 'logic');
        $result = $FaqLogic->getList($params);

        if($result)
        {
            return json(['code'=>0,'msg'=>'success','data'=>$result]);
        }

        return json(['code'=>102,'msg'=>'数据为空','data'=>[]]);

    }

}